import sys
import pygame
from Settings import Settings
from Ship import Ship

class AlienInvasion:
    """管理游戏资源和行为的类"""
    def __init__(self):
        #初始化游戏并创建游戏资源
        pygame.init()
        self.clock=pygame.time.Clock()
        self.settings=Settings()
        self.screen=pygame.display.set_mode((self.settings.screen_width,self.settings.screen_height))
        pygame.display.set_caption("Alien Invasion")
        self.bg_color=(0,191,255)
        self.ship=Ship(self)
    def run_game(self):
        #开始游戏主循环
        while True:
            self._check_events()
            #让最近绘制的屏幕可见
            self._update_screen()
            self.clock.tick(60)

    def _check_events(self):
        for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    sys.exit()
    def _update_screen(self):
         self.screen.fill(self.settings.bg_color)
         self.ship.blitme()
         pygame.display.flip()
if __name__=="__main__":
    ai=AlienInvasion()
    ai.run_game()
